<?php
class masterbarang_model extends CI_Model{
	private $KodeBarang;
    private $Productname;
    private $Typeunit;
  	private $Description;
    private $CreatedBy;
    private $CreatedOn;
    private $LastUpdateBy;
  	private $LastUpdateOn;
  	private $Active;
	
	function setKodeBarang($KodeBarang){
		$this->KodeBarang = $KodeBarang;
	}

	function getKodeBarang(){
		return $this->KodeBarang;
	}
	
	function setProductname($Productname){
		$this->Productname = $Productname;
	}

	function getProductname(){
		return $this->Productname;
	}
	
	function setTypeunit($Typeunit){
		$this->Typeunit = $Typeunit;
	}

	function getTypeunit(){
		return $this->Typeunit;
	}
	
	function setDescription($Description){
		$this->Description = $Description;
	}

	function getDescription(){
		return $this->Description;
	}
	
	function setCreatedBy($c_by){
		$this->createdby = $c_by;
	}

	function getCreatedBy(){
		return $this->createdby;
	}

	function setCreatedOn($dateNow){
		//$dateNow = date('Y-m-d H:i:s');
		$this->createdon = $dateNow;
	}

	function getCreatedOn(){
		return $this->createdon;
	}

	function setLastUpdateBy($u_by){
		$this->lastupdateby = $u_by;
	}

	function getLastUpdateBy(){
		return $this->lastupdateby;
	}

	function setLastUpdateOn($dateNow){
		//$dateNow = date('Y-m-d H:i:s');
		$this->lastupdateon = $dateNow;
	}

	function getLastUpdateOn(){
		return $this->lastupdateon;
	}

	function setActive($active_val){
		$this->active = $active_val;
	}

	function getActive(){
		return $this->active;
	}
	
	// Call the module constructor
	function __construct(){
		parent::__construct();
	}
	
	function insert(){
		
		$data = array(
			'KodeBarang' => $this->getKodeBarang(),
			'Productname' => $this->getProductname(),
			'Typeunit' => $this->getTypeunit(),
			'Description' => $this->getDescription(),
			'createdby' => $this->getCreatedBy(),
			'createdon' => $this->getCreatedOn(),
			'Lastupdateby' => $this->getLastupdateby(),
			'Lastupdateon' => $this->getLastupdateon(),
			'active' => '1'					
		);
		
		$this->db->insert('product_header',$data);
	}
	
	function ubahmasterbarang() 
	{
            $data = array(
                'Productname' => $this->getProductname(),
                'Typeunit' => $this->getTypeunit(),
                'Description' => $this->getDescription(),
                'Lastupdateby' => $this->getLastupdateby(),
				'Lastupdateon' => $this->getLastupdateon(),
            );
 
        $this->db->where(array('KodeBarang' => $this->getKodeBarang()));
        $this->db->update('product_header', $data);
    }

    function deletemasterbarang() {
        $data = array(
            'active' => '0'
        );
        $this->db->where(array('KodeBarang' => $this->getKodeBarang()));
        $this->db->update('product_header', $data);
    }
	
	function getList(){
		$this->db->select()->where(array('active'=>'1'));
		$this->db->order_by('KodeBarang', 'asc');
		$query = $this->db->get('product_header');
		return $query->result();
	}
	
	function countGetList(){
		$this->db->select()->where(array('active'=>'1'));
		$this->db->order_by('KodeBarang', 'asc');
		$query = $this->db->get('product_header');
		return $query->num_rows();
	}
	
	function getListlimit($limit,$start){
		$this->db->select()
		->where(array('active'=>'1'))
		->limit($limit,$start);
		$this->db->order_by('KodeBarang', 'asc');
		$query = $this->db->get('product_header');
		return $query->result();
	}
	
	function getBarangByKode()
	{
		$this->db->select()->where(array('KodeBarang' => $this->getKodeBarang(),'active'=>'1'));
		$query = $this->db->get('product_header');
		return $query->result();
	}
	
	function getkdbaranglike(){
		$this->db->select()
		->where(array('Active'=>'1'))->like(array('KodeBarang' => $this->getKodeBarang()));
		$query = $this->db->get('product_header');
		return $query->result();
	}
	
	function getnamabaranglike(){
		$this->db->select()
		->where(array('Active'=>'1'))->like(array('Productname' => $this->getProductname()));
		$query = $this->db->get('product_header');
		return $query->result();
	}
}